import * as querystring from 'querystring';

const gateway = process.env.NODE_ENV === 'development' ? 'http://localhost:5000/' : '/';
const pageRoot = '';
export const HttpMethod = {
  get: 'get',
  post: 'post',
  put: 'put',
  delete: 'delete',
};
export default {

  // 页面路由
  pageRoutes: {
    root: '/',
    installIndex: pageRoot + '/install',
    projectIndex: pageRoot + '/project',
    projectIndexParams: (searchParams?: any) => `${pageRoot}/project?${querystring.stringify(searchParams)}`,

    projectEdit: pageRoot + '/project/edit/:id',
    projectEditParams: (id: any) => pageRoot + `/project/edit/${id}`,
    projectCreate: pageRoot + '/project/create',
    projectEnvLogIndex: pageRoot + '/project/:projectId/env/:envId/log',
    projectEnvLogInfo: pageRoot + '/project/:projectId/env/:envId/log/:seq',
    projectEnvLogInfoParams: (projectId: any, envId: any, seq?: any) => {
      let value = pageRoot + `/project/${projectId}/env/${envId}/log`;
      if (seq)
        value = pageRoot + `/project/${projectId}/env/${envId}/log/${seq}`;
      return value;
    },
    // 版本计划
    planIndex: pageRoot + '/plan',
    planProjectSort: pageRoot + '/plan/project-sort',
    planCreate: pageRoot + '/plan/create',
    planInfo: pageRoot + '/plan/:id',
    planInfoParams: (id: any) => pageRoot + `/plan/${id}`,
    planEdit: pageRoot + '/plan/edit/:id',
    planEditParams: (id: any) => pageRoot + `/plan/edit/${id}`,


    userIndex: pageRoot + '/user',
    userCreate: pageRoot + '/user/create',
    userEdit: pageRoot + '/user/edit/:id',
    userEditParams: (id: any) => pageRoot + `/user/edit/${id}`,
    userLogin: pageRoot + '/user/login',

    serverIndex: pageRoot + '/server',
    serverCreate: pageRoot + '/server/create',
    serverEdit: pageRoot + '/server/edit/:id',
    serverEditParams: (id: any) => pageRoot + `/server/edit/${id}`,

    envIndex: pageRoot + '/env',
    envCreate: pageRoot + '/env/create',
    envEdit: pageRoot + '/env/edit/:id',
    envEditParams: (id: any) => pageRoot + `/env/edit/${id}`,


    // 插件注册中心
    pluginRegisterCenterIndex: pageRoot + '/plugin/register-center',
    // 插件 Eureka
    pluginIndex: pageRoot + '/plugin',
    pluginEurekaIndex: pageRoot + '/plugin/register-center/eureka',
    pluginEurekaEnvIndex: pageRoot + '/plugin/register-center/eureka/envId/:id',
    pluginEurekaEnvIndexParams: (envId: any) => pageRoot + `/plugin/register-center/eureka/envId/${envId}`,
    pluginEurekaEnvSetting: pageRoot + '/plugin/register-center/eureka/env-setting',

    // 插件 Nacos
    pluginNacosIndex: pageRoot + '/plugin/register-center/nacos',
    pluginNacosEnvIndex: pageRoot + '/plugin/register-center/nacos/envId/:id',
    pluginNacosEnvIndexParams: (envId: any) => pageRoot + `/plugin/register-center/nacos/envId/${envId}`,
    pluginNacosEnvSetting: pageRoot + '/plugin/register-center/nacos/env-setting',

    // 插件 阿里云监控
    pluginAliyunMonitorIndex: pageRoot + '/plugin/aliyun-monitor',
    pluginAliyunMonitorECSSetting: pageRoot + '/plugin/aliyun-monitor/ecs-setting',
    pluginAliyunMonitorAccessKeySetting: pageRoot + '/plugin/aliyun-monitor/accesskey-setting',

    pluginAliyunMonitorSLBSetting: pageRoot + '/plugin/aliyun-monitor/slb-setting',
    pluginAliyunMonitorSLBSettingCreate: pageRoot + '/plugin/aliyun-monitor/slb-setting/create',

    pluginAliyunMonitorPolardbSetting: pageRoot + '/plugin/aliyun-monitor/polardb-setting',
    pluginAliyunMonitorPolardbSettingCreate: pageRoot + '/plugin/aliyun-monitor/polardb-setting/create',

    pluginAliyunMonitorRedisSetting: pageRoot + '/plugin/aliyun-monitor/redis-setting',
    pluginAliyunMonitorRedisSettingCreate: pageRoot + '/plugin/aliyun-monitor/redis-setting/create',

    pluginAliyunMonitorRocketmqSetting: pageRoot + '/plugin/aliyun-monitor/rocketmq-setting',
    pluginAliyunMonitorRocketmqSettingCreate: pageRoot + '/plugin/aliyun-monitor/rocketmq-setting/create',
  },
  // API
  apiRoutes: {

    systemInstall: {
      url: gateway + 'api/systems/install',
      method: HttpMethod.post,
    },
    systemInstalled: {
      url: gateway + 'api/systems/installed',
      method: HttpMethod.get,
    },
    projectPage: (searchParams?: any) => ({
      url: `${gateway}api/projects/page?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    projectInfo: (searchParams?: any) => ({
      url: `${gateway}api/projects/info?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    projectSave: (payload?: any) => ({
      url: `${gateway}api/projects/save`,
      method: HttpMethod.post,
      data: payload,
    }),
    projectUpdate: (payload?: any) => ({
      url: `${gateway}api/projects/update`,
      method: HttpMethod.put,
      data: payload,
    }),
    projectDelete: (payload?: any) => ({
      url: `${gateway}api/projects/delete`,
      method: HttpMethod.delete,
      data: payload,
    }),

    projectBuild: (payload?: any) => ({
      url: `${gateway}api/projects/build`,
      method: HttpMethod.post,
      data: payload,
    }),
    projectSync: (payload?: any) => ({
      url: `${gateway}api/projects/sync`,
      method: HttpMethod.post,
      data: payload,
    }),

    projectDynamicPublish: (payload?: any) => ({
      url: `${gateway}api/projects/dynamic-publish`,
      method: HttpMethod.post,
      data: payload,
    }),

    projectInit: (payload?: any) => ({
      url: `${gateway}api/projects/init`,
      method: HttpMethod.post,
      data: payload,
    }),

    projectRefreshBranch: (payload?: any) => ({
      url: `${gateway}api/projects/refreshBranch`,
      method: HttpMethod.post,
      data: payload,
    }),

    envList: (searchParams?: any) => ({
      url: `${gateway}api/envs/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),

    serverList: (searchParams?: any) => ({
      url: `${gateway}api/servers/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),

    projectEnvList: (searchParams?: any) => ({
      url: `${gateway}api/projectEnvs/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    projectEnvServerList: (searchParams?: any) => ({
      url: `${gateway}api/projectEnvServers/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),

    projectEnvInfo: gateway + 'api/projectEnvs/info',
    projectEnvPluginInfo: (searchParams?: any) => ({
      url: `${gateway}api/projectEnvPlugins/info?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    projectEnvPluginList: (searchParams?: any) => ({
      url: `${gateway}api/projectEnvPlugins/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    projectEnvLogList: (searchParams?: any) => ({ url: `${gateway}api/projectEnvLogs/list?${querystring.stringify(searchParams)}` }),
    projectEnvLogInfo: (searchParams?: any) => ({ url: `${gateway}api/projectEnvLogs/info?${querystring.stringify(searchParams)}` }),

    userLogin: { url: gateway + 'api/users/login', method: HttpMethod.post },
    userPage: gateway + 'api/users/page',
    userSave: gateway + 'api/users/save',
    userInfo: gateway + 'api/users/info',
    userDelete: {
      url: gateway + 'api/users/delete',
      method: HttpMethod.delete,
    },
    userUpdate: gateway + 'api/users/update',

    serverPage: { url: gateway + 'api/servers/page', method: HttpMethod.get },
    serverUpdate: { url: gateway + 'api/servers/update', method: HttpMethod.put },
    serverUpdateMonitor: { url: gateway + 'api/servers/updateMonitor', method: HttpMethod.put },
    serverSave: { url: gateway + 'api/servers/save', method: HttpMethod.post },
    serverInfo: { url: gateway + 'api/servers/info', method: HttpMethod.get },
    serverDelete: { url: gateway + 'api/servers/delete', method: HttpMethod.delete },

    // 插件环境配置
    pluginEnvSettingInfo: (searchParams?: any) => ({
      url: `${gateway}api/pluginEnvSetting/info?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    pluginEnvSettingList: (searchParams?: any) => ({
      url: `${gateway}api/pluginEnvSetting/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    pluginEnvSettingSave: (payload?: any) => ({
      url: `${gateway}api/pluginEnvSetting/save`,
      method: HttpMethod.post,
      data: payload,
    }),


    envPage: (searchParams?: any) => {
      return { url: `${gateway}api/envs/page?${querystring.stringify(searchParams)}`, method: HttpMethod.get };
    },
    planPage: (searchParams?: any) => {
      return { url: `${gateway}api/plans/page?${querystring.stringify(searchParams)}`, method: HttpMethod.get };
    },
    planProjectSortList: (searchParams?: any) => {
      return {
        url: `${gateway}api/plans/project-sort-list?${querystring.stringify(searchParams)}`,
        method: HttpMethod.get,
      };
    },
    planProjectSortSetting: (payload?: any) => ({
      url: `${gateway}api/plans/project-sort-setting`,
      method: HttpMethod.post,
      data: payload,
    }),
    planInfo: (searchParams?: any) => ({
      url: `${gateway}api/plans/info?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    planSave: (payload?: any) => {
      return { url: `${gateway}api/plans/save`, method: HttpMethod.post, data: payload };
    },
    planUpdate: (payload?: any) => {
      return { url: `${gateway}api/plans/update`, method: HttpMethod.put, data: payload };
    },
    planDelete: (payload: any) => ({ url: gateway + 'api/envs/delete', method: HttpMethod.delete, data: payload }),

    planGrayPublish: (payload?: any) => {
      return { url: `${gateway}api/plans/gray-publish`, method: HttpMethod.post, data: payload };
    },


    envUpdate: { url: gateway + 'api/envs/update', method: HttpMethod.put },
    envSave: { url: gateway + 'api/envs/save', method: HttpMethod.post },
    envInfo: { url: gateway + 'api/envs/info', method: HttpMethod.get },
    envDelete: { url: gateway + 'api/envs/delete', method: HttpMethod.delete },

    // 插件
    pluginList: (searchParams?: any) => ({
      url: `${gateway}api/plugin/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),

    // 插件 第三方 api
    // Eureka
    // 应用列表
    pluginEurekaList: (searchParams?: any) => ({
      url: `${gateway}api/plugin/eureka/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    // 修改应用状态
    pluginEurekaStatus: (payload?: any) => ({
      url: `${gateway}api/plugin/eureka/status`,
      method: HttpMethod.put,
      data: payload,
    }),

    // Nacos
    // 应用列表
    pluginNacosInstanceList: (searchParams?: any) => ({
      url: `${gateway}api/plugin/nacos/service/list?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),

    // 修改应用状态
    pluginNacosInstanceChangeStatus: (payload?: any) => ({
      url: `${gateway}api/plugin/nacos/instance/changeStatus`,
      method: HttpMethod.put,
      data: payload,
    }),


    // 阿里云监控

    // 服务器监控
    pluginAliyunMonitor: (searchParams?: any) => ({
      url: `${gateway}api/plugin/monitor?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),

    // 配置阿里云子账号 accessKey  Id and Secret
    pluginAliyunSettingAccountAccessKeyIdAndSecret: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-accesskey/settingIdAndSecret`,
      method: HttpMethod.post,
      data: payload,
    }),
    // 配置阿里云 SLB
    pluginAliyunSLBPage: (searchParams?: any) => ({
      url: `${gateway}api/plugin/aliyun-slb/page?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    // 配置阿里云 SLB 保存
    pluginAliyunSLBSave: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-slb/save`,
      method: HttpMethod.post,
      data: payload,
    }),
    // 配置阿里云 SLB 更新是否监控
    pluginAliyunSLBUpdateMonitor: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-slb/updateMonitor`,
      method: HttpMethod.put,
      data: payload,
    }),
    // 配置阿里云 SLB 删除
    pluginAliyunSLBDelete: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-slb/delete`,
      method: HttpMethod.delete,
      data: payload,
    }),


    // 配置阿里云 Polardb
    pluginAliyunPolardbPage: (searchParams?: any) => ({
      url: `${gateway}api/plugin/aliyun-polardb/page?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    // 配置阿里云 Polardb 保存
    pluginAliyunPolardbSave: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-polardb/save`,
      method: HttpMethod.post,
      data: payload,
    }),
    // 配置阿里云 Polardb 更新是否监控
    pluginAliyunPolardbUpdateMonitor: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-polardb/updateMonitor`,
      method: HttpMethod.put,
      data: payload,
    }),
    // 配置阿里云 Polardb 删除
    pluginAliyunPolardbDelete: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-polardb/delete`,
      method: HttpMethod.delete,
      data: payload,
    }),

    // 配置阿里云 Redis
    pluginAliyunRedisPage: (searchParams?: any) => ({
      url: `${gateway}api/plugin/aliyun-redis/page?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    // 配置阿里云 Redis 保存
    pluginAliyunRedisSave: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-redis/save`,
      method: HttpMethod.post,
      data: payload,
    }),
    // 配置阿里云 Redis 更新是否监控
    pluginAliyunRedisUpdateMonitor: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-redis/updateMonitor`,
      method: HttpMethod.put,
      data: payload,
    }),
    // 配置阿里云 Redis 删除
    pluginAliyunRedisDelete: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-redis/delete`,
      method: HttpMethod.delete,
      data: payload,
    }),


    // 配置阿里云 Rocketmq
    pluginAliyunRocketmqPage: (searchParams?: any) => ({
      url: `${gateway}api/plugin/aliyun-rocketmq/page?${querystring.stringify(searchParams)}`,
      method: HttpMethod.get,
    }),
    // 配置阿里云 Rocketmq 保存
    pluginAliyunRocketmqSave: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-rocketmq/save`,
      method: HttpMethod.post,
      data: payload,
    }),
    // 配置阿里云 Rocketmq 更新是否监控
    pluginAliyunRocketmqUpdateMonitor: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-rocketmq/updateMonitor`,
      method: HttpMethod.put,
      data: payload,
    }),
    // 配置阿里云 Rocketmq 删除
    pluginAliyunRocketmqDelete: (payload?: any) => ({
      url: `${gateway}api/plugin/aliyun-rocketmq/delete`,
      method: HttpMethod.delete,
      data: payload,
    }),
  },
};

